package com.zenithsun.web;

import com.alibaba.druid.support.json.JSONUtils;

import java.io.Serializable;

/**
 * 返回通用类
 * @param <T>
 */
public class ResponseEntity<T> implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * 返回码代号
     */
    private ResultCodeEnum code;
    /**
     * 返回码揭示信息
     */
    private String message;
    /**
     * 返回数据
     */
    private  T data;

    public ResponseEntity() {
    }
    /**
     * 反回错误码
     * @return
     */
    public ResultCodeEnum getCode() {
        return code;
    }

    /**
     * 设置返回错误码
     * @param resultCode
     * @return
     */
    public ResponseEntity setCode(ResultCodeEnum resultCode) {
        this.code = resultCode;
        return this;
    }
    public String getMessage() {
        return message;
    }
    public ResponseEntity setMessage(String message) {
        this.message = message;
        return this;
    }
    public T getData() {
        return data;
    }
    public ResponseEntity setData(T data) {
        this.data = data;
        return this;
    }

    /**
     * 将对象转为json
     * @return
     */
    public String toJsonString (){
       return JSONUtils.toJSONString(this);
    }
}
